<template>
    <div>
        <el-dialog :title="title" :visible.sync="open" width="60%" destroy-on-close append-to-body>
            <el-form :model="formData" size="small" label-width="120px" ref="form">
                <el-form-item label="任务内容" prop="cate">
                    {{ formData.taskContent }}
                </el-form-item>
                <el-form-item label="辅助信息" prop="cate">
                    {{ formData.helpContent }}
                </el-form-item>
                <el-form-item label="子任务" prop="cate">
                    <el-table :data="sonTasks" border>
                        <el-table-column prop="receiveUserName" label="执行人" width="180"></el-table-column>
                        <el-table-column label="任务内容" align="left" prop="taskContent" />
                        <el-table-column label="任务状态" align="left" prop="helpContent">
                            <template slot-scope="scope">
                                <el-tag type="warning" v-if="scope.row.status == 0" size="mini">待下发</el-tag>
                                <el-tag type="primary" v-if="scope.row.status == 1" size="mini">执行中</el-tag>
                                <el-tag type="success" v-if="scope.row.status == 2" size="mini">已完成</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250">
                            <template slot-scope="scope">
                                <el-button @click="handleSonTaskDetail(scope.row)" type="text" size="small">任务详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="close">确 定</el-button>
            </div>
        </el-dialog>
        <SonTaskDetail ref="sonTaskDetail" />
    </div>
</template>

<script>
import dialogMixin from "@/mixins/dialogMixin";
import { getTaskDetail } from "@/api/response/task";
import { getHandleSonTaskList } from "@/api/response/handle";
import SonTaskDetail from "./HandleSonTaskDetail.vue";

export default {
    name: "HandleDetailDialog",
    mixins: [dialogMixin],
    components: { SonTaskDetail },
    data() {
        return {
            title: "任务详情",
            open: false,
            formData: {
                attachs: [],
            },
            sonTasks: [],
        };
    },
    methods: {
        //完成任务调
        showDialog(data) {
            getTaskDetail(data.id).then(res => {
                this.formData = res.data;
                if (this.formData.parentId == "0") {
                    this.getSonTasks();
                }
                this.open = true;
            });
        },
        getSonTasks() {
            getHandleSonTaskList(this.formData.id).then(res => {
                this.sonTasks = res.data;
            });
        },
        handleTaskAttachDownload(row) {
            // 下载附件
            this.download(`com/ComAttach/download/${row.attachid}`, {}, `${row.attachname}.${row.attachtype}`);
        },
        handleSonTaskDetail(row) {
            this.$refs.sonTaskDetail.showDialog(row);
        },
    },
};
</script>

<style lang="scss" scoped>
.task-report {
    padding: 0 20px 20px;
}
</style>
